/**
 * @Author: easten
 * @Created: 2024-08-11 00:39:07
 * @Description: 用户管理接口
 *
 */
import { SysUser } from "_common/entity";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";
export class ApiUser {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/sys/user";

  /**
   * @description 构造函数
   * @param config axios 配置
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }

  /** 创建用户 */
  createUser(data: SysUser) {
    return this.request.post<boolean>(this.url + "/create", data);
  }

  /** 更新用户 */
  updateUser(data: SysUser) {
    return this.request.put<boolean>(this.url + "/update", data);
  }

  /** 删除用户 */
  deleteUser(id: number) {
    return this.request.delete<boolean>(this.url + "/delete/" + id);
  }

  /** 获取用户信息 */
  getUserInfo(id: number) {
    return this.request.get<SysUser>(this.url + "/get-user", { id });
  }

  /** 获取用户列表 */
  getUserList(params: any) {
    return this.request.get<SysUser[]>(this.url + "/get-list", params);
  }

  // 获取用户分页列表
  getPageList(params: any) {
    return this.request.get<any>(this.url + "/get-page", params);
  }

  /** 修改用户状态 */
  changeStatus(params: { id: number; status: boolean }) {
    return this.request.get<boolean>(this.url + "/change-status", params);
  }

  // 获取用户的角色ids
  getUserRoleIds(id: number) {
    return this.request.get<number[]>(this.url + "/get-role-ids/" + id);
  }
}
